<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>计算属性 方法和侦听器</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <div>{{msg}}</div>
        <div>计算属性：{{fullName}}</div>
        <div>方法：{{fullNameMethod()}}</div>
        <div>侦听器：{{fullNameWatch}}</div>
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                msg: 'I love vue!',
                firstName: 'yyy',
                lastName: 'ttt',
                fullNameWatch: '111 222',
                count: 0
            },
            // 方法
            methods: {
                fullNameMethod: function(){
                    return this.firstName + ' ' + this.lastName;
                }
            },
            // 计算属性
            computed: {
                fullName: function(){
                    console.log("计算了一次");
                    return this.firstName + ' ' + this.lastName ;
                }
            },

            // 侦听器
            watch: {
                firstName: function(){
                    this.fullNameWatch = this.firstName + ' ' + this.lastName;
                },
                lastName: function(){
                    this.fullNameWatch = this.firstName + ' ' + this.lastName;
                }
            }
        });
    </script>
</body>
</html>